home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / ZSI / generate / pyclass.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  6KB  |  161 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import pydoc
  5. import sys
  6. import warnings
  7. from ZSI import TC
  8.  
  9. def _x():
  10.     pass
  11.  
  12.  
  13. try:
  14.     _x.func_name = '_y'
  15. except:
  16.     raise RuntimeError, 'use python-2.4 or later, cannot set function names in python "%s"' % sys.version
  17.  
  18. del _x
  19.  
  20. class pyclass_type(type):
  21.     
  22.     def __new__(cls, classname, bases, classdict):
  23.         typecode = classdict.get('typecode')
  24.         if len(bases) > 0:
  25.             pass
  26.         elif typecode.mixed:
  27.             (get, set) = cls._pyclass_type__create_text_functions_from_what(typecode)
  28.             if classdict.has_key(get.__name__):
  29.                 raise AttributeError, 'attribute %s previously defined.' % get.__name__
  30.             
  31.             if classdict.has_key(set.__name__):
  32.                 raise AttributeError, 'attribute %s previously defined.' % set.__name__
  33.             
  34.             classdict[get.__name__] = get
  35.             classdict[set.__name__] = set
  36.         
  37.         for what in typecode.ofwhat:
  38.             (get, set, new_func) = cls._pyclass_type__create_functions_from_what(what)
  39.             if classdict.has_key(get.__name__):
  40.                 raise AttributeError, 'attribute %s previously defined.' % get.__name__
  41.             
  42.             classdict[get.__name__] = get
  43.             if classdict.has_key(set.__name__):
  44.                 raise AttributeError, 'attribute %s previously defined.' % set.__name__
  45.             
  46.             classdict[set.__name__] = set
  47.             if new_func is not None:
  48.                 if classdict.has_key(new_func.__name__):
  49.                     raise AttributeError, 'attribute %s previously defined.' % new_func.__name__
  50.                 
  51.                 classdict[new_func.__name__] = new_func
  52.             
  53.             pname = what.pname
  54.             if pname is None and isinstance(what, TC.AnyElement):
  55.                 pname = 'any'
  56.             
  57.             pname = pname[0].upper() + pname[1:]
  58.             classdict[pname] = property(get, set, None, 'property for element (%s,%s), minOccurs="%s" maxOccurs="%s" nillable="%s"' % (what.nspname, what.pname, what.minOccurs, what.maxOccurs, what.nillable))
  59.         
  60.         if hasattr(typecode, 'attribute_typecode_dict'):
  61.             if not typecode.attribute_typecode_dict:
  62.                 pass
  63.             attribute_typecode_dict = { }
  64.             for key, what in attribute_typecode_dict.items():
  65.                 (get, set) = cls._pyclass_type__create_attr_functions_from_what(key, what)
  66.                 if classdict.has_key(get.__name__):
  67.                     raise AttributeError, 'attribute %s previously defined.' % get.__name__
  68.                 
  69.                 if classdict.has_key(set.__name__):
  70.                     raise AttributeError, 'attribute %s previously defined.' % set.__name__
  71.                 
  72.                 classdict[get.__name__] = get
  73.                 classdict[set.__name__] = set
  74.             
  75.         
  76.         return type.__new__(cls, classname, bases, classdict)
  77.  
  78.     
  79.     def __create_functions_from_what(what):
  80.         if not callable(what) and getattr(what, 'pyclass', None) is None:
  81.             new_func = None
  82.         elif isinstance(what, TC.ComplexType) or isinstance(what, TC.Array):
  83.             
  84.             def new_func(self):
  85.                 return what.pyclass()
  86.  
  87.         elif not callable(what):
  88.             
  89.             def new_func(self, value):
  90.                 return what.pyclass(value)
  91.  
  92.         elif issubclass(what.klass, TC.ComplexType) or issubclass(what.klass, TC.Array):
  93.             
  94.             def new_func(self):
  95.                 p = what().pyclass
  96.                 if p is None:
  97.                     return None
  98.                 
  99.                 return p()
  100.  
  101.         else:
  102.             
  103.             def new_func(self, value = (None,)):
  104.                 p = what().pyclass
  105.                 if p is None:
  106.                     return None
  107.                 
  108.                 if value is None:
  109.                     return p()
  110.                 
  111.                 return p(value)
  112.  
  113.         if new_func is not None:
  114.             new_func.__name__ = 'new_%s' % what.pname
  115.         
  116.         get.func_name = 'get_element_%s' % what.pname
  117.         set.func_name = 'set_element_%s' % what.pname
  118.         return (get, set, new_func)
  119.  
  120.     __create_functions_from_what = staticmethod(__create_functions_from_what)
  121.     
  122.     def __create_attr_functions_from_what(key, what):
  123.         
  124.         def get(self):
  125.             'returns attribute value for attribute %s, else None.\n            ' % str(key)
  126.             return getattr(self, what.attrs_aname, { }).get(key, None)
  127.  
  128.         
  129.         def set(self, value):
  130.             'set value for attribute %s.\n            value -- initialize value, immutable type\n            ' % str(key)
  131.             if not hasattr(self, what.attrs_aname):
  132.                 setattr(self, what.attrs_aname, { })
  133.             
  134.             getattr(self, what.attrs_aname)[key] = value
  135.  
  136.         if type(key) in (tuple, list):
  137.             get.__name__ = 'get_attribute_%s' % key[1]
  138.             set.__name__ = 'set_attribute_%s' % key[1]
  139.         else:
  140.             get.__name__ = 'get_attribute_%s' % key
  141.             set.__name__ = 'set_attribute_%s' % key
  142.         return (get, set)
  143.  
  144.     __create_attr_functions_from_what = staticmethod(__create_attr_functions_from_what)
  145.     
  146.     def __create_text_functions_from_what(what):
  147.         
  148.         def get(self):
  149.             return getattr(self, what.mixed_aname, None)
  150.  
  151.         get.im_func = 'get_text'
  152.         
  153.         def set(self, value):
  154.             setattr(self, what.mixed_aname, value)
  155.  
  156.         get.im_func = 'set_text'
  157.         return (get, set)
  158.  
  159.     __create_text_functions_from_what = staticmethod(__create_text_functions_from_what)
  160.  
  161.